/**
 * https://leetcode.cn/problems/minimum-size-subarray-sum/description/
 * 209. 长度最小的子数组
 * medium, 赖德檀 2024.09.04
 * 滑动窗口
 */

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int sum=0;
        int len=INT_MAX;
        for(int l=0,r=0;r<nums.size();r++)
        {
            if(sum+nums[r]>=target)
            {
                len=min(len,r-l+1);
                sum-=nums[l++];
                r--;
            }
            else
            sum+=nums[r];
        }
        return len==INT_MAX?0:len;
    }
};